import requests
import lxml
import lxml.etree
class BiAnSpider():
    def __init__(self):
        self.url='http://pic.netbian.com/e/search/result/?searchid='+str(1223)
        self.headers = {  #模拟请求头
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4015.0 Safari/537.36"
        }

    def get_html(self):
        response = requests.get(
            url=self.url,
            headers=self.headers
        )
        # 解决乱码
        response.encoding = response.apparent_encoding
        mytree = lxml.etree.HTML(response.text)  #调用xpath解析库
        return mytree
    
    def search_img(self):
        html=self.get_html()
        imgurl_list=[]
        for imgurl in html.xpath('//ul[@class="clearfix"]/li/a/img/@src'):  #调用可xpath解析库才能 获取dom
            if imgurl:
                base_url='http://pic.netbian.com/'+imgurl
                imgurl_list.append(base_url)
            
        print(imgurl_list)    


if __name__ == "__main__":
    spider=BiAnSpider()
    print(spider.search_img())
# 